// 输入：num1 = "11", num2 = "123"
// 输出："134"
var addStrings = function (num1, num2) {
  let result = [];
  let carry = 0;
  num1 = num1.split("").reverse();
  num2 = num2.split("").reverse();
  for (let i = 0; i < num1.length || i < num2.length; i++) {
    let x = num1[i] ? num1[i] - 0 : 0;
    let y = num2[i] ? num2[i] - 0 : 0;
    let sum = x + y + carry;

    result.push(sum % 10); //!重要

    carry = Math.floor(sum / 10); // 更新进位
  }
  //最后如果还有进位
  if (carry > 0) {
    result.push(carry);
  }

  //!join方法拼接
  return result.reverse().join("");
};

console.log(addStrings("456", "77"));
